import React, { Component } from 'react';
import { observer, inject } from 'mobx-react';
import moment from 'moment';
import { observable, action, toJS } from 'mobx';
import { Tools, Modal, Badge, Avatar } from 'weaver-mobile';
import { withRouter, Route } from 'react-router-dom';
import { ListViewPage } from 'weaver-mobile-page';
import RemindStore from './../../stores/remind/RemindStore';
import RemindItem from './RemindItem';
// import ContacterLogs from './../sellChanceListNew/ContacteLogs';
const alert = Modal.alert;

const isIPhone = new RegExp('\\biPhone\\b|\\biPod\\b', 'i').test(window.navigator.userAgent);
let wrapProps;
if (isIPhone) {
    wrapProps = {
        onTouchStart: e => e.preventDefault(),
    };
}
const getLabel = Tools.getLabel;
@withRouter
@observer
export default class RemindList extends Component {
    constructor(props) {
        super(props);
        this.state = {
            store: new RemindStore(),
            sellChanceId: "",
        }
    }
    index = 0;
    currentChance = "";
    tip = "";
    componentWillMount() {
        const { doNew } = this.state.store;
        doNew(this, this.props.params);
    }
    doInIt = (e) => {
        const { doInIt } = this.state.store;
        doInIt({ tabKey: this.state.tabKey }, this.props.params);
    }
    render() {
        const { list, doInIt } = this.state.store;
        const tabProps = {
            onTabClick: (tab) => {
                doInIt({ tabKey: tab.tabKey });
                this.setState({ tabKey: tab.tabKey });
            },
        };
        return (
            <div className="crm-remind-main">
                <div className="crm-remind-main-list">
                    <ListViewPage.Normal
                        store={list}
                        getTemplate={this.getTemplate}
                    />
                </div>
            </div>
        )
    }

    getTemplate = (template) => {
        let today = moment().format('YYYY-MM-DD');
        let yestoday = moment().add('days', -1).format('YYYY-MM-DD');
        const { onHrmCardClick, onOpenContact, onCustomerClick, onSellChanceClick, onContacterClick } = this.props
        const newTemp = {
            default: [{
                key: 'col_1',
                render: (data) => {
                    const { createdate } = data;
                    if (createdate != this.currentData) {
                        this.currentData = createdate;
                        this.index = 0;
                    }
                    if (createdate == today) {
                        this.tip = getLabel('514760', '今日提醒');
                    } else if (createdate == yestoday) {
                        this.tip = getLabel('514761', '昨日提醒');
                    } else if (createdate == '1900-01-01') {
                        this.tip = getLabel('514762', '未提醒');
                    } else {
                        this.tip = createdate;
                    }
                    this.index++;

                    return (
                        <div className='crm-remind-main-item'>
                            {this.index == 1 && <div className="wm-list-view-page-modal-nomore">
                                <span className="wm-list-view-page-modal-nomore-line-left"></span>
                                <span className="wm-list-view-page-modal-nomore-line-name">{this.tip}</span>
                                <span className="wm-list-view-page-modal-nomore-line-right"></span>
                            </div>}
                            <RemindItem
                                data={data}
                                obj={this}//当前对象
                                showDrop={false}
                                onHrmCardClick={onHrmCardClick}
                                onOpenContact={onOpenContact}
                                onCustomerClick={onCustomerClick}
                                onSellChanceClick={onSellChanceClick}
                                onContacterClick={onContacterClick}
                            />
                        </div>
                    );
                },
            }],
        };
        return newTemp;
    }
}